<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>资源管理-添加客户</title>
<style type="text/css">
.marginLeft {
	margin-left:10px;
}
</style>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/validate.jsp"%>
<script type="text/javascript" src="common/js/jquery/chinaArea/chinaArea.js"></script>
<script type="text/javascript">
	function chinaAreaSelectCallback(selectText) {
		if (selectText && selectText != "") {
			$("#label_area").text(selectText);
			$("#customer_area").val(selectText);
		}
    }
    
    function jsonDataCallback(json) {
        var checkBoxs = $("#productCategorysDiv");
        checkBoxs.html("");
        var list = json.categoryList;
        $.each(list, function(i, o) {
        	var checkbox = $("<input type='checkbox' value='" + o.id + "'/>");
        	checkbox.attr("txtValue", o.name);
        	if ($("#span-" + o.id).length > 0) {
        		checkbox.attr("checked", true);
        	}
	       	checkBoxs.append(checkbox);
	       	checkBoxs.append("<label>" + o.name + "</label>");
        });
    }
    
	$(document).ready(function() {
		$("#saveCustomer").validate({
			submitHandler: function(form) {
				form.submit();
				self.returnValue = DIALOG_RESULT_TYPE_SUCCESS;
				self.close();
				return false;
			}
		});
		
		$("#root_category").bind("change", function() {
			var parentId = $(this).val();
			var url="queryMaterialsCategoryJOSN.action?categoryId=" + parentId + "&temp=" + new Date();
			$.getJSON(url, jsonDataCallback);
		});
		var checkBoxs = $("#productCategorysDiv");
		var resultBoxs = $("#selectProductCategorysDiv");
		checkBoxs.click(function(e){
			if (e.target.type && e.target.type == "checkbox") {
				var select = $(e.target);
				if (select.attr("checked")) {
					var span = $("<span id='span-" + select.val() + "' class='marginLeft'>" + select.attr("txtValue")
							+ "<input type='hidden' name='productCategorys' value='" + select.val() + "' /></span>");
					resultBoxs.append(span);
				} else {
					$("#span-" + select.val()).remove();
				}
	        }
		});
	});
	
	function btn_save() {
    	$("#saveCustomer").submit();
    	//self.returnValue = DIALOG_RESULT_TYPE_SUCCESS;
    	//self.close();
	}
</script>
</head>
<base target="_self">
<body>
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">基础数据管理</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">添加客户</span></td>
		  </tr>
		</table>
      </div>
     <s:fielderror />
     <div class="main_1">
       <s:form action="saveCustomer">
       <s:if test="customer.id>0">
         <s:hidden name="customer.id"/>
         <s:hidden name="customer.createDate"/>
       </s:if>
       <table width="100%" border="0" cellpadding="10" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td bgcolor="#FAFAFA"><table width="100%" border="0" cellpadding="5" cellspacing="1"  >
             <tr>
               <td width="13%" class="gr-text1"><div align="right"><strong>地区</strong></div></td>
               <td width="87%" align="left">
               	 <s:textfield name="customer.area" size="20" cssClass="{required:true,maxlength:20}" />
               	 <span class="red-text1">*</span>
               </td>
             </tr>
             <tr>
               <td class="gr-text1"><div align="right"><strong>客户名称</strong></div></td>
               <td align="left">
               	 <s:textfield name="customer.name" size="30" cssClass="{required:true,maxlength:30}" />
               	 <span class="red-text1">*</span>
               </td>
             </tr>
             <tr>
               <td class="gr-text1" rowspan="2"><div align="right"><strong>产品分类</strong></div></td>
               <td align="left">
	          	<s:select id="root_category"
	          	    name="notUseRootCategory"
	          		list="categoryList"
	          		listKey="id"
	          		listValue="name"
	          		headerKey="-1"
	          		headerValue="-请选择-" />
               </td>
             </tr>
             <tr>
               <td align="left">
                 <div id="productCategorysDiv" />
               </td>
             </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>已经选择的分类</strong></div></td>
               <td align="left">
				  <div id="selectProductCategorysDiv" style="width:100%; height:100%">
				    <s:iterator value="customer.productCategorys" id="category" status="st">
				        <span id='span-<s:property value="#category.id" />' class="marginLeft">
						  <s:property value="#category.name" />
						  <s:hidden name="productCategorys" value="%{#category.id}" />
				        </span>
				    </s:iterator>
				  </div>
               </td>
			 </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>地址</strong></div></td>
               <td align="left">
               	 <s:textfield name="customer.address" size="60" cssClass="{required:true,maxlength:60}" />
               	 <span class="red-text1">*</span>
               </td>
			 </tr>
			  <tr>
               <td class="gr-text1"><div align="right"><strong>联系人</strong></div></td>
               <td align="left">
               	 <s:textfield name="customer.contact" size="10" cssClass="{required:true,maxlength:10}" />
               	 <span class="red-text1">*</span>
			   </td>
             </tr>
             <tr>
               <td class="gr-text1"><div align="right"><strong>联系电话</strong></div></td>
               <td align="left">
               	 <s:textfield name="customer.phone" size="15" cssClass="{required:true,maxlength:15,digits:true}" />
               	 <span class="red-text1">*</span>
               </td>
             </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>传真</strong></div></td>
               <td align="left">
                 <s:textfield name="customer.fax" size="15" />
               </td>
			 </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>邮箱</strong></div></td>
               <td align="left">
                 <s:textfield name="customer.email" size="50" />
               </td>
			 </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>开票名称</strong></div></td>
               <td align="left">
                 <s:textfield name="customer.taxName" size="30" cssClass="{maxlength:20}" />
               </td>
			 </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>税号</strong></div></td>
               <td align="left">
                 <s:textfield name="customer.taxNo" size="30" cssClass="{digits:true}" />
			   </td>
             </tr>
			 <tr>
               <td class="gr-text1"><div align="right"><strong>备注</strong></div></td>
               <td align="left">
                 <s:textarea name="customer.remark" rows="5" cssClass="textarea2"/>
			   </td>
             </tr>
             <tr>
               <td valign="top"></td>
               <td align="left"><input type="button" value="保存" class="input1" onclick="btn_save()"/>&nbsp;&nbsp;
               <input type="button" value="关闭" class="input1" onclick='self.close();' />
               </td>
             </tr>
             
           </table></td>
         </tr>
      </table>
  	  </s:form>
    </div>
    <div class="clear"></div>
</body>
</base>
</html>
